package com.ruoyi.project.erp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.erp.dto.WorkLogApprovalDto;
import com.ruoyi.project.erp.dto.WorklogApprovalQuery;
import com.ruoyi.project.erp.vo.WorklogApprovalVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.erp.domain.WorklogApproval;
import com.ruoyi.project.erp.service.IWorklogApprovalService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 工时审批流Controller
 * 
 * @author ruoyi
 * @date 2025-06-19
 */
@RestController
@RequestMapping("/erp/approval")
public class WorklogApprovalController extends BaseController
{
    @Autowired
    private IWorklogApprovalService worklogApprovalService;

    /**
     * 查询工时审批列表
     */
    @PreAuthorize("@ss.hasPermi('erp:approval:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorklogApprovalQuery query)
    {
        startPage();
        // ★★★ 方法名已修改 ★★★
        List<WorklogApprovalVO> list = worklogApprovalService.selectList(query);
        return getDataTable(list);
    }

    /**
     * 导出工时审批流列表
     */
    @PreAuthorize("@ss.hasPermi('erp:approval:export')")
    @Log(title = "工时审批流", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorklogApproval worklogApproval)
    {
        List<WorklogApproval> list = worklogApprovalService.selectWorklogApprovalList(worklogApproval);
        ExcelUtil<WorklogApproval> util = new ExcelUtil<WorklogApproval>(WorklogApproval.class);
        util.exportExcel(response, list, "工时审批流数据");
    }

    /**
     * 获取工时审批流详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:approval:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(worklogApprovalService.selectWorklogApprovalById(id));
    }

    /**
     * 新增工时审批流
     */
    @PreAuthorize("@ss.hasPermi('erp:approval:add')")
    @Log(title = "工时审批流", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorklogApproval worklogApproval)
    {
        return toAjax(worklogApprovalService.insertWorklogApproval(worklogApproval));
    }

    /**
     *工时审批
     */
    @PostMapping("/workLogApproval")
    public AjaxResult workLogApproval(@RequestBody WorkLogApprovalDto dto)
    {
        return toAjax(worklogApprovalService.workLogApproval(dto));
    }

    /**
     * 修改工时审批流
     */
    @PreAuthorize("@ss.hasPermi('erp:approval:edit')")
    @Log(title = "工时审批流", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorklogApproval worklogApproval)
    {
        return toAjax(worklogApprovalService.updateWorklogApproval(worklogApproval));
    }

    /**
     * 删除工时审批流
     */
    @PreAuthorize("@ss.hasPermi('erp:approval:remove')")
    @Log(title = "工时审批流", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(worklogApprovalService.deleteWorklogApprovalByIds(ids));
    }
}
